package com.tang.web_standard.global.response;

/**
 * @Author tangyuan2meicloud.com
 * @DATE 2021/9/16 19:42
 * @Desc
 * @Remarks
 */
public class ResultBuilder {

    public static final Result DEFAULT_RESULT = ok(null);

    private String msg;
    private Integer code;
    private Object data;

    public ResultBuilder setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public ResultBuilder setCode(Integer code) {
        this.code = code;
        return this;
    }

    public ResultBuilder setData(Object data) {
        this.data = data;
        return this;
    }

    public Result build() {
        Result result = new Result();
        result.setMsg(msg);
        result.setData(data);
        result.setCode(code);
        return result;
    }

    static public Result error(Object data) {
        Result result = new Result();
        result.setMsg("Error");
        result.setData(data);
        result.setCode(500);
        return result;
    }

    static public Result ok(Object data) {
        Result result = new Result();
        result.setMsg("Ok");
        result.setData(data);
        result.setCode(200);
        return result;
    }

}
